﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;

namespace 话务台来电外放
{
    public class DbHelperSQL
    {
        /// <summary>
        /// 读取配置文件，根据行得到数据
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public string GetZy(int h)
        {
            string strData = "";
            StreamReader sr = new StreamReader("zy.jx");
            for (int i = 0; i < h; i++)
            {
                strData = sr.ReadLine();
            }
            return strData;
        }

        /// <summary>
        /// 判断数据库是否连接成功
        /// </summary>
        public bool OpenRequest(string SqlConnectionString)
        {
            #region
            try
            {
                SqlConnection cn = new SqlConnection(SqlConnectionString);
                cn.Open();
                if (cn != null)
                {
                    cn.Close();
                    cn.Dispose();
                }
                return true;
            }
            catch
            {
                return false;
            }
            #endregion
        }

        /// <summary>
        /// 查询SQL语句返回第一行第一列
        /// </summary>
        /// <param name="sq"></param>
        /// <returns></returns>
        public string SqlGetData(string sql,string strConn)
        {
            string ss = "";
            SqlConnection con = new SqlConnection();
            con.ConnectionString = strConn;
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandType = CommandType.Text;
            com.CommandText = sql;
            SqlDataReader myReader = com.ExecuteReader();
            myReader.Read();
            ss = myReader[0].ToString();
            con.Close();
            return ss;
        }
    }
}
